<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.io.IOException"%>
<%@page import="java.net.URL"%>
<%@page import="java.net.HttpURLConnection"%>
<%@page import="java.io.BufferedReader"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.net.URLEncoder"%>
<%
String info=request.getParameter("message").toString();
String result=getTulingApi(info);
out.print("var info="+result+";");

%>
<%!
/**
调用图灵api方法
**/	
	public String getTulingApi(String info)throws IOException{
		StringBuffer result=new StringBuffer();
		info=URLEncoder.encode(info,"utf-8");
		String reqUrl="http://www.tuling123.com/openapi/api?key=1879aa8844744c9397d279d46f8cf47e&info="+info;
		URL url=new URL(reqUrl);
		//打开连接
		HttpURLConnection connection=(HttpURLConnection)url.openConnection();
		connection.connect();//连接url
		//io流 stream字节流 reader字符流  字节流转换字符流
		connection.getInputStream();
		BufferedReader reader=new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));
		String line ;
		while((line=reader.readLine())!=null){
			result.append(line);
		}
		return result.toString();
	}
 %>

